//
//  LZGroupsViewController.m
//  LZEasemob3
//
//  Created by nacker on 16/8/29.
//  Copyright © 2016年 帶頭二哥 QQ:648959. All rights reserved.
//

#import "LZGroupsViewController.h"
#import "LZCreateGroupViewController.h"
#import "SRRefreshView.h"
#import "BaseTableViewCell.h"

@interface LZGroupsViewController ()<UISearchBarDelegate, UISearchDisplayDelegate, EMGroupManagerDelegate, SRRefreshDelegate>

@property (strong, nonatomic) NSMutableArray *dataSource;

@property (strong, nonatomic) SRRefreshView *slimeView;

@end

@implementation LZGroupsViewController

//#pragma mark - getter
//- (SRRefreshView *)slimeView
//{
//    if (_slimeView == nil) {
//        _slimeView = [[SRRefreshView alloc] init];
//        _slimeView.delegate = self;
//        _slimeView.upInset = 0;
//        _slimeView.slimeMissWhenGoingBack = YES;
//        _slimeView.slime.bodyColor = [UIColor grayColor];
//        _slimeView.slime.skinColor = [UIColor grayColor];
//        _slimeView.slime.lineWith = 1;
//        _slimeView.slime.shadowBlur = 4;
//        _slimeView.slime.shadowColor = [UIColor grayColor];
//    }
//    return _slimeView;
//}
//
//- (NSMutableArray *)dataSource
//{
//    if (_dataSource == nil){
//        self.dataSource = [NSMutableArray array];
//    }
//    return _dataSource;
//}
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    
//    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
//    {
//        [self setEdgesForExtendedLayout:UIRectEdgeNone];
//    }
//    self.title = NSLocalizedString(@"title.group", @"Group");
//    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    self.tableView.backgroundColor = [UIColor whiteColor];
//    
//#warning 把self注册为SDK的delegate
//    [[EMClient sharedClient].groupManager removeDelegate:self];
//    [[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];
//    
//    [self.tableView addSubview:self.slimeView];
//    
//    [self reloadDataSource];
//}
//
//#pragma mark - SRRefreshDelegate
//
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    [_slimeView scrollViewDidScroll];
//}
//
//- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
//{
//    [_slimeView scrollViewDidEndDraging];
//}
//
//- (void)slimeRefreshStartRefresh:(SRRefreshView *)refreshView
//{
//    __weak typeof(self) weakself = self;
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        EMError *error = nil;
//        NSArray *groups = [[EMClient sharedClient].groupManager getMyGroupsFromServerWithError:&error];
//        dispatch_async(dispatch_get_main_queue(), ^{
//            if (!error) {
//                [weakself.dataSource removeAllObjects];
//                [weakself.dataSource addObjectsFromArray:groups];
//                [weakself.tableView reloadData];
//            }
//            [weakself.slimeView endRefresh];
//        });
//    });
//}
//
//#pragma mark - EMGroupManagerDelegate
//
//- (void)didUpdateGroupList:(NSArray *)groupList
//{
//    [self.dataSource removeAllObjects];
//    [self.dataSource addObjectsFromArray:groupList];
//    [self.tableView reloadData];
//}
//
//#pragma mark - data
//
//- (void)reloadDataSource
//{
//    [self.dataSource removeAllObjects];
//    
//    NSArray *rooms = [[EMClient sharedClient].groupManager getJoinedGroups];
//    [self.dataSource addObjectsFromArray:rooms];
//    
//    [self.tableView reloadData];
//}
//
//
//#pragma mark - Table view data source
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 2;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    if (section == 0) {
//        return 2;
//    }
//    return [self.dataSource count];
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    static NSString *CellIdentifier = @"GroupCell";
//    BaseTableViewCell *cell = (BaseTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//    if (cell == nil) {
//        cell = [[BaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//    }
//    
//    if (indexPath.section == 0) {
//        switch (indexPath.row) {
//            case 0:
//                cell.textLabel.text = NSLocalizedString(@"group.create.group",@"Create a group");
//                cell.imageView.image = [UIImage imageNamed:@"group_creategroup"];
//                break;
//            case 1:
//                cell.textLabel.text = NSLocalizedString(@"group.create.join",@"Join public group");
//                cell.imageView.image = [UIImage imageNamed:@"group_joinpublicgroup"];
//                break;
//            default:
//                break;
//        }
//    } else {
//        EMGroup *group = [self.dataSource objectAtIndex:indexPath.row];
//        NSString *imageName = @"group_header";
////        NSString *imageName = group.isPublic ? @"groupPublicHeader" : @"groupPrivateHeader";
//        cell.imageView.image = [UIImage imageNamed:imageName];
//        if (group.subject && group.subject.length > 0) {
//            cell.textLabel.text = group.subject;
//        }
//        else {
//            cell.textLabel.text = group.groupId;
//        }
//    }
//    
//    return cell;
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 50;
//}
//
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indeweakselfxPath
//{
//    return UITableViewCellEditingStyleDelete;
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    if (section == 0) return 0;
//    return 22;
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    if (section == 0)
//    {
//        return nil;
//    }
//    
//    UIView *contentView = [[UIView alloc] init];
//    [contentView setBackgroundColor:[UIColor colorWithRed:0.88 green:0.88 blue:0.88 alpha:1.0]];
//    return contentView;
//}
//
//#pragma mark - action
//- (void)showPublicGroupList
//{
//    UIViewController *publicController = [[UIViewController alloc] init];
//    [self.navigationController pushViewController:publicController animated:YES];
//}
//
//- (void)createGroup
//{
//    LZCreateGroupViewController *createGroupVC = [[LZCreateGroupViewController alloc] init];
//    [self.navigationController pushViewController:createGroupVC animated:YES];
//}
@end
